package com.consumer.asyncTask;

import com.consumer.config.NumConstants;
import com.consumer.entity.TPlane;
import com.consumer.entity.TProductPlane;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.concurrent.BlockingQueue;

@Service
public class ExecuteTask {

    private AsyncTask asyncTask;
    public ExecuteTask(AsyncTask asyncTask) {
        this.asyncTask = asyncTask;
    }
    public void startTasks(BlockingQueue<String> queue) {
        //查询所有的
        for (int i = 0; i < 10; i++) {
            while (!queue.isEmpty()) {
                try {
                    String take = queue.take();
                    System.out.println("项目任务迁移第" + NumConstants.count++ + "个");
                    asyncTask.migrateProject(take);
                } catch (Exception e) {
                    System.out.println(e.getMessage());
                }
            }
        }
    }

    public void startProductTasks(BlockingQueue<String> queue) {
        int count = 0;
        for (int i = 0; i < 10; i++) {
            while (!queue.isEmpty()) {
                try {
                    String take = queue.take();
                    System.out.println("产品任务迁移第" + NumConstants.count2++ + "个");
                    asyncTask.migrateProduct(take);
                } catch (Exception e) {
                    System.out.println(e.getMessage());
                }
            }
        }
    }

    public void createProjectBucket(BlockingQueue<TPlane> queue) {
        int count = 0;
        for (int i = 0; i < 10; i++) {
            while (!queue.isEmpty()) {
                try {
                    TPlane take = queue.take();
                    System.out.println("项目" + take.getPlaneName() + "创建桶，第" + NumConstants.count3++ + "个项目");
                    asyncTask.createProjectBucket(take);
                } catch (Exception e) {
                    System.out.println(e.getMessage());
                }
            }
        }
    }

    public void createProductBucket(BlockingQueue<TProductPlane> queue) {
        int count = 0;
        for (int i = 0; i < 10; i++) {
            while (!queue.isEmpty()) {
                try {
                    TProductPlane take = queue.take();
                  System.out.println("产品" + take.getProductPlaneName() + "创建桶，第" + NumConstants.count4++ + "个产品");
                    asyncTask.createProductBucket(take);
                } catch (Exception e) {
                    System.out.println(e.getMessage());
                }
            }
        }
    }

    public void moveProjectBucketFile(BlockingQueue<TPlane> queue) {
        for (int i = 0; i < 10; i++) {
            while (!queue.isEmpty()) {
                try {
                    TPlane take = queue.take();
                    if (StringUtils.isNotBlank(take.getSystemId())) {
                        asyncTask.moveProjectBucketFile(take);
                    } else {
                        System.out.println(take + "系统ID为空");
                    }
                } catch (Exception e) {
                    System.out.println(e.getMessage());
                }
            }
        }
    }

    public void moveProductBucketFile(BlockingQueue<TProductPlane> queue) {
        for (int i = 0; i < 10; i++) {
            while (!queue.isEmpty()) {
                try {
                    TProductPlane take = queue.take();
                    if (StringUtils.isNotBlank(take.getSystemId())) {
                        asyncTask.moveProductBucketFile(take);
                    } else {
                        System.out.println(take + "系统ID为空");
                    }
                } catch (Exception e) {
                    System.out.println(e.getMessage());
                }
            }
        }
    }
}
